package cn.etgps.etgps.base;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.etgps.etgps.R;
import cn.etgps.etgps.view.MyTitleBar;

/**
 * Created by itte on 2016/3/28.
 */
public abstract class MyBasicActivity<PM extends BasePresenter> extends BaseActivity {
    @Bind(R.id.title_bar)
    protected MyTitleBar titleBar;
    protected PM mPresenter;
    protected Context mContext;

    protected abstract void setTitle();

    protected abstract int getLayoutId();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        mContext = this;
        setTitle();
        titleBar.setLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        initPresenter();
        initView(savedInstanceState);

    }

    protected void initView(Bundle savedInstanceState) {

    }

    protected void initPresenter() {

    }

    /***
     * 通过Class跳转界面
     **/
    protected void startActivity(Class<?> cls) {
        startActivity(cls, null);
    }

    /**
     * 含有Bundle通过Class跳转界面
     **/
    protected void startActivity(Class<?> cls, Bundle bundle) {
        Intent intent = new Intent();
        intent.setClass(mContext, cls);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }

    /**
     * 通过Action跳转界面
     **/
    protected void startActivity(String action, Uri uri) {
        Intent intent = new Intent(action, uri);
        startActivity(intent);
    }

    /**
     * 含有Bundle通过Action跳转界面
     **/
    protected void startActivity(String action, Bundle bundle) {
        Intent intent = new Intent();
        intent.setAction(action);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }
}
